var User_Review = function () {

    return {
        init: function () {
            
            gridviewScroll($('.portlet-table').width());
            
            $('table.data-user tr').hover(function () {
                $('td',this).addClass('hover');
            }, function () {
                $('td',this).removeClass('hover');
            });
    
            function gridviewScroll(_width) { 

                $('table.data-user').gridviewScroll({ 
                    width: _width,
                    height: 500,
                    railcolor: "#F0F0F0",
                    barcolor: "#CDCDCD",
                    barhovercolor: "#606060",
                    bgcolor: "#F0F0F0",
                    varrowtopimg: "assets/img/arrowvt.png",
                    varrowbottomimg: "assets/img/arrowvb.png",
                    harrowleftimg: "assets/img/arrowhl.png",
                    harrowrightimg: "assets/img/arrowhr.png",
                    freezesize: 1,
                    headerrowcount: 2,
                    arrowsize: 40,
                    railsize: 20,
                    barsize: 20
                }); 
            }
            
            $('td.set-rank').click(function () {
                var obj = {};
                obj['classid'] = $(this).attr('classid');
                obj['username'] = $(this).attr('username');
                obj['rank'] = $(this).attr('rank');
                obj['note'] = $(this).attr('note');
                
                $('#responsive').html(tmpl('rank-tmpl', obj));
                
                $('#responsive').modal({
                    focusOn: 'input:text'
                })
                .find('.btn-save').click(function () {
                    
                    var tmp_inputs = $("input, textarea, select", $('#responsive'));
                    var obj = {};
                    
                    $.map(tmp_inputs, function(n, i) {
                    
                        obj[$(n).attr('name')] = $(n).val();
                    });
                    
                    $('[classid="'+obj.classid+'"]')
                    .html('<img src="assets/img/loading.gif"/>')
                    
                    $.ajax({
                        url: 'review_execute.php?action=update-rank',
                        type: 'post',
                        dataType: 'json',
                        data: $.param(obj),
                        success:function(response){
                            if (response.code = 200) {
                                $('[classid="'+response.data.classid+'"]')
                                .html(response.data.rankname)
                                .attr('note', response.data.note)
                                .attr('rank', response.data.rank);
                            }
                        }
                    });
                    
                    $('.close','#responsive').click();
                });
            });
        }
    };
}();